import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  DefaultValuePipe,
  ParseIntPipe,
  UseGuards,
} from '@nestjs/common';
import { PermissionService } from 'src/service/permission.service';
import { CreatePermissionDto } from 'src/dto/create-permission.dto';
import { UpdatePermissionDto } from 'src/dto/update-permission.dto';
import { AdminGuard } from 'src/guards/admin.guard';

@UseGuards(AdminGuard)
@Controller('admin/permission')
export class PermissionController {
  constructor(private readonly PermissionService: PermissionService) {}

  @Post()
  create(@Body() createPermissionDto: CreatePermissionDto) {
    return this.PermissionService.create(createPermissionDto);
  }

  @Get()
  findAll(
    @Query('pageNum', new DefaultValuePipe(1), ParseIntPipe) pageNum: number,
    @Query('pageSize', new DefaultValuePipe(10), ParseIntPipe) pageSize: number,
  ) {
    return this.PermissionService.findAll(pageNum, pageSize);
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.PermissionService.findOne(+id);
  }

  @Patch(':id')
  update(
    @Param('id') id: string,
    @Body() updatePermissionDto: UpdatePermissionDto,
  ) {
    return this.PermissionService.update(+id, updatePermissionDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.PermissionService.remove(+id);
  }
}
